#include "Stack.h"


void ST::Init(int DefaultCapacity)
{
	STDataType* ret = (STDataType*)calloc(DefaultCapacity, sizeof(STDataType));
	if (!ret)
	{
		perror("calloc");
		return;
	}
	data = ret;
	top = 0;
	capacity = DefaultCapacity;
	ret = nullptr;
}
void ST::Push(STDataType x)
{
	if (top == capacity)
	{
		STDataType* ret = (STDataType*)realloc(data,capacity * 2 * sizeof(STDataType));
		if (!ret)
		{
			perror("realloc");
			return;
		}
		data = ret;
		capacity *= 2;
		ret = nullptr;
	}
	data[top++] = x;

}
